package ghelp

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// HttpResponseResult 统一返回格式
type HttpResponseResult struct {
	Code int64       `json:"code" ` // 错误码，0：表示成功；其它错误码：表示有错误
	Msg  string      `json:"msg"`   // 错误码描述信息
	Data interface{} `json:"data"`  // 业务数据
}

// ResponseResult 发送http返回内容
func ResponseResult(c *gin.Context, res HttpResponseResult) {
	c.JSON(http.StatusOK, res)
}

// ResponseSuccess 发送http成功内容
func ResponseSuccess(c *gin.Context, data interface{}) {
	ResponseResult(c, HttpResponseResult{
		Code: 0,
		Msg:  "success",
		Data: data,
	})
}

// ResponseFail 发送http失败内容
func ResponseFail(c *gin.Context, msg string) {
	ResponseResult(c, HttpResponseResult{
		Code: 0,
		Msg:  msg,
		Data: nil,
	})
}
